package com.itheima.admin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.dto.AdSensitivePageRequestDto;
import com.itheima.admin.mapper.AdSensitiveMapper;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.admin.pojo.AdSensitive;
import com.itheima.admin.service.AdSensitiveService;
import com.itheima.common.vo.PageResultVo;
import org.springframework.stereotype.Service;

/**
 * @version 1.0
 * @description 标题
 * @package com.itheima.admin.service.impl
 */
@Service
public class AdSensitiveServiceImpl extends ServiceImpl<AdSensitiveMapper, AdSensitive> implements AdSensitiveService {

    /**
     * 敏感词分页查询
     *
     * @param dto
     * @return
     */
    @Override
    public PageResultVo findPage(AdSensitivePageRequestDto dto) {
        //1. 创建分页对象
        IPage<AdSensitive> pageInfo = new Page(dto.getPage(),dto.getSize());
        //2. 创建条件对象
        LambdaQueryWrapper<AdSensitive> lqw = new LambdaQueryWrapper<>();
        lqw.like(StrUtil.isEmpty(dto.getName()),AdSensitive::getSensitives,dto.getName());
        //3. 执行查询
        IPage<AdSensitive> pageResult = page(pageInfo, lqw);
        System.out.println("pageResult==pageInfo:::" + (pageResult==pageInfo));
        //4. 封装对象
        return PageResultVo.pageResult(dto.getPage(),dto.getSize(),pageInfo.getTotal(),pageInfo.getRecords());
    }
}
